<%@ page import="per.hnvcam.searchext.data.model.Word" %>
<%@ page import="java.util.Map" %>
<%@ page import="per.hnvcam.searchext.data.model.WordCount" %>
<%@ page import="per.hnvcam.searchext.data.model.WebReference" %>
<%@ page import="java.util.List" %>
<%--
  Created by IntelliJ IDEA.
  User: camhoang
  Date: 8/2/11
  Time: 1:54 PM
  To change this template use File | Settings | File Templates.
--%>
<%@include file="include.jsp"%>
<%
   pageTitle = "Words summary";
   configurationTile = "Words Summary";
%>
<%@include file="header.jsp"%>

      <h3><a href="<c:url value='/administration/wordsSummary.jhtml?operation=fuzzy'/>">Determine words amount</a></h3>
      <br/>
      <table border="1" cellpadding="3" cellspacing="0" style="empty-cells: show;">
         <tr>
            <th width="10px">No</th>
            <th width="80px">Word Label</th>
            <th width="10px">Max Count</th>
            <% int pageIndex = 0; %>
            <c:forEach items="${pages}" var="pageItem">
               <th colspan="2" width="30px"><a
                  href="<c:url value='/administration/page.jhtml?pageId=${pageItem.id}' />">Page <%=++pageIndex%></a></th>
            </c:forEach>
         </tr>
         <%
            int currentPage = Integer.parseInt(request.getAttribute("currentPage").toString());
            int count = (currentPage - 1) * 100;
            Map<Long, Map<Long, WordCount>> wordMap = (Map<Long, Map<Long, WordCount>>) request.getAttribute("wordMap");
            List<Word> wordList = (List<Word>) request.getAttribute("wordList");
            for (Word word : wordList) {
         %>
         <tr>
            <td><%= ++count%>
            </td>
            <td><%=word.getLabel()%>
            </td>
            <td><%=word.getMaxCount()%>
            </td>
            <% for (WebReference pageItem : (List<WebReference>) request.getAttribute("pages")) {
               Map<Long, WordCount> countList = wordMap.get(word.getId());
               if (countList != null) {
                  WordCount wc = countList.get(pageItem.getId());
                  if (wc != null) {
                     out.write("<td>" + wc.getCount() + "</td>");
                     String fuzzyAmount = wc.getFuzzyAmount();
                     if (fuzzyAmount != null && !fuzzyAmount.equals("")) {
                        out.write("<td class='cell_has_value'>" + wc.getFuzzyAmount() + "</td>");
                     } else {
                        out.write("<td></td>");
                     }
                     continue;
                  }
               }
               out.write("<td></td><td></td>");
            } %>
         </tr>
         <% } %>
      </table>
      <c:if test="${previousPage ne null}">
            <a href="<c:url value='/administration/wordsSummary.jhtml?page=${previousPage}'/>">Previous</a>&nbsp;|&nbsp;
      </c:if>
      ${currentPage}
      <c:if test="${nextPage ne null}">
            &nbsp;|&nbsp;<a href="<c:url value='/administration/wordsSummary.jhtml?page=${nextPage}'/>">Next</a>
      </c:if>

<%@include file="footer.jsp"%>